#pragma once

#include <string.h>

#include <algorithm>
#include <list>
#include <map>
#include <mutex>
#include <string>

#include "bondlib.h"

class S_BONDLIB_EXPORT BondDict {
 public:
  BondDict();
  BondDict(const BondDict& rhs);
  ~BondDict();
  BondDict& operator=(const BondDict& rhs);

  char selective_code[32];
  char* selective_content;
  char* selective_content_en;
  char sortcode[4];
  char group_name[32];
  char group_name_original[32];
  char selective_code_original[32];
  void SetSelectiveContent(const char* content);
  void SetSelectiveContentEn(const char* content);

  const bool operator<(const BondDict& obj) const {
    if (strcmp(group_name, obj.group_name) < 0)
      return true;
    else if (strcmp(group_name, obj.group_name) == 0 &&
             strcmp(selective_code, obj.selective_code) < 0)
      return true;
    return false;
  }
  const bool operator==(const BondDict& obj) {
    if (strcmp(group_name, obj.group_name) == 0 &&
        strcmp(selective_code, obj.selective_code) == 0)
      return true;
    return false;
  }

 private:
  static char Empty;
};

class CBondList {
 public:
  // std::list<BondDict> m_list;
  std::map<std::string, BondDict>
      m_list;  //<group_name.selective_code,BondDict>
};

class S_BONDLIB_EXPORT CBondDict {
 public:
  static CBondDict& instance();

 public:
  CBondList* GetBondArrByGroup(const std::string& sGroup, bool bInsert = false);
  bool GetBondDict(const char* sGroup, const char* sCode, BondDict& stDict);

  bool Add(BondDict& dict);
  bool Clear();
  int GetSize();
  std::mutex& GetMutex() { return m_mutex; };

 public:
  void DumpStatus(int mode = 0) const;

 private:
  CBondDict();
  virtual ~CBondDict();

 protected:
  std::map<std::string, CBondList*> m_map;
  std::mutex m_mutex;
};
